package com.example.mybatisdemo.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mybatisdemo.config.DynamicDataSourceHolder;
import com.example.mybatisdemo.domain.entity.Incident;
import com.example.mybatisdemo.domain.entity.TestEntity;
import com.example.mybatisdemo.domain.param.TestParam;
import com.example.mybatisdemo.domain.returns.RespEntity;
import com.example.mybatisdemo.mapper.IncidentMapper;
import com.example.mybatisdemo.mapper.TestMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dynamic-data-source")
public class DynamicDataSourceController {

    @Resource
    private TestMapper testMapper;
    @Resource
    private IncidentMapper incidentMapper;

    @GetMapping("/test")
    public RespEntity test(){

        return RespEntity.success();
    }


    @GetMapping("/incident")
    public RespEntity incident(){
        DynamicDataSourceHolder.setManualDBType("linkage");
        List<Incident> entityList = incidentMapper.selectList(new QueryWrapper<Incident>().last("limit 3"));
        return RespEntity.success(entityList);
    }



}
